/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.TextField
 *  javafx.scene.layout.GridPane
 *  javafx.scene.text.Text
 *  org.springframework.util.StringUtils
 */
package com.gys.controller.example;

import com.gys.controller.BaseController;
import com.gys.controller.dataManger.ControllerManger;
import com.gys.controller.example.ExampleController;
import com.gys.data.example.GetProductBaseInData;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import org.springframework.util.StringUtils;

@FXMLController
public class EditProductController
extends BaseController
implements Initializable {
    @FXML
    private GridPane editProduct;
    @FXML
    private Text id;
    @FXML
    private TextField productName;
    @FXML
    private TextField productNum;

    public void initialize(URL location, ResourceBundle resources) {
        ControllerManger.controllerMap.put(this.getClass().getSimpleName(), this);
        this.initForm();
    }

    protected void initForm() {
        ExampleController exampleController = (ExampleController)ControllerManger.controllerMap.get(ExampleController.class.getSimpleName());
        this.id.setText(exampleController.editProductData.getId().toString());
        this.productName.setText(exampleController.editProductData.getProductName());
        this.productNum.setText(exampleController.editProductData.getProductNum().toString());
    }

    @FXML
    private void editProduct() {
        String idStr = this.id.getText().trim();
        String productNameStr = this.productName.getText().trim();
        String productNumStr = this.productNum.getText().trim();
        Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", null);
        if (StringUtils.isEmpty(productNameStr) || StringUtils.isEmpty(productNumStr)) {
            alert.setContentText("\u5546\u54c1\u540d\u79f0\u6216\u6570\u91cf\u4e0d\u80fd\u4e3a\u7a7a\uff01");
            alert.showAndWait();
            return;
        }
        ExampleController exampleController = (ExampleController)ControllerManger.controllerMap.get(ExampleController.class.getSimpleName());
        GetProductBaseInData inData = new GetProductBaseInData();
        inData.setId(Long.valueOf(idStr));
        inData.setProductName(productNameStr);
        inData.setProductNum(Integer.valueOf(productNumStr));
        exampleController.refreshTable();
        this.cancel();
    }

    @FXML
    private void cancel() {
        this.editProduct.getScene().getWindow().hide();
    }
}

